package com.jh.user.repository;

import com.jh.user.pojo.ShopRegister;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ShopRegisterRepository extends
        JpaRepository<ShopRegister,String>,
        JpaSpecificationExecutor<ShopRegister>{

    ShopRegister findById(Long id);

    @Query("select s from ShopRegister s where s.shopName like %:shopName% and s.status = '5'")
    List<ShopRegister> findByShopName(@Param("shopName") String shopName);

    ShopRegister findByShopId(/*@Param("shopId")*/ String shopId);

    ShopRegister findByUserId(/*@Param("UserId")*/ String UserId);

    List<ShopRegister> findShopRegistersByAgentPhone(String agentPhone);

    @Query(value = "select shopRegister from ShopRegister shopRegister where shopRegister.mobilePhone = :mobilePhone and shopRegister.status = '5'")
    ShopRegister findByMobilePhone(@Param("mobilePhone")String mobilePhone);

    @Query(value = "select shopRegister from ShopRegister shopRegister where shopRegister.userId = :userId")
    ShopRegister findByUserId(@Param("userId") Long userId);

    @Query("select s from ShopRegister s where s.userId = :userId and s.shopId = :merchantNo")
    ShopRegister getByUserIdAndShopId(@Param("userId") long userId, @Param("merchantNo") String merchantNo);

    @Query("select s from ShopRegister s where s.userId = :userId and s.status = '5'")
    ShopRegister findShopByUserId(@Param("userId") long userId);

    @Query("select s from ShopRegister s where s.shopId = :shopId and s.status = 5")
    ShopRegister getByShopId(@Param("shopId") String shopId);

    @Query("select s from ShopRegister s where s.shopId = :shopId and s.brandId = :brandId and s.status = :status")
    ShopRegister getShopRegisterByShopId(@Param("shopId") String shopId, @Param("brandId") long brandId, @Param("status") int status);

    @Query("select s from ShopRegister s where s.userId = :userId and s.brandId = :brandId and s.status = :status")
    ShopRegister findShopRegister(@Param("userId") long userId, @Param("brandId") long brandId, @Param("status") int status);

    @Query(value = "select shopRegister from ShopRegister shopRegister where shopRegister.mobilePhone = :mobilePhone")
    ShopRegister findByMobile(@Param("mobilePhone") String mobilePhone);
}
